package com.lukk.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lukk.pojo.InternalWorker;
import com.lukk.pojo.Province;
import com.lukk.pojo.Territory;
import com.lukk.service.IProvinceService;

/**
 * 
 * ProvinceController 下午1:19:00 Copyright zhaocj Inc. All Rights reserved.
 * alldios@outlook.com
 *
 */
@Controller
@RequestMapping("/province")
public class ProvinceController {
	private static Logger logger = LogManager.getLogger(ProvinceController.class.getName());
	@Autowired
	private IProvinceService provinceService;

	public IProvinceService getProvinceService() {
		return provinceService;
	}

	public void setProvinceService(IProvinceService provinceService) {
		this.provinceService = provinceService;
	}

	@RequestMapping("/queryUnallocatedProvinces")
	// 查询还没有分配的省份
	public @ResponseBody List<Province> queryUnallocatedProvinces() {
		return provinceService.selectUnallocatedProvinces();
	}

	@RequestMapping("/queryAvailableProvinces")
	// 查询还没有分配的省份
	public @ResponseBody Map<String, List<Province>> queryAvailableProvincesByInternalWorker(
			InternalWorker internalWorker) {
		return provinceService.selectAvailableProvinces(internalWorker);
	}

	@RequestMapping("/queryProvinces")
	// 查询还没有分配的省份
	public @ResponseBody List<Province> queryProvinces() {
		return provinceService.selectProvinces();
	}

	// 查询登陆员工的省份
	@RequestMapping("/queryAllocatedProvinces")
	// 查询还没有分配的省份
	public @ResponseBody List<Province> queryAllocatedProvincesForInternalWorker(HttpSession session) {
		return provinceService.selectAllocatedProvincesForInternalWorker(session);
	}

	@RequestMapping("/modifyProvincesByInternalWorker")
	public @ResponseBody boolean modifyProvincesByInternalWorker(String provinceIDS, InternalWorker internalWorker) {
		provinceService.modifyProvincesByInternalWorker(provinceIDS, internalWorker);
		return true;
	}

	@RequestMapping("/selectByProvinceCode")
	public @ResponseBody List<Territory> selectByProvinceCode(String provinceCode) {
		return provinceService.selectCityByProvinceCode(provinceCode);
	}

	@RequestMapping("/countByCity")
	public @ResponseBody Map<String, Object> countByCity(String cityCode) {
		return provinceService.selectCountByCity(cityCode);

	}

	// 根据省份Code返回省份表格
	@RequestMapping("/countTableByProvince")
	public @ResponseBody Map<String, Object> countByProvince(String provinceCode) {
		return provinceService.selectTableCountByProvinceCode(provinceCode);

	}

	// 查询登陆员工的省份
	@RequestMapping("/queryAllocatedProvincesByIWorker")
	// 查询还没有分配的省份
	public @ResponseBody List<Province> queryAllocatedProvincesByIWorker(Integer iWorkerID) {
		return provinceService.selectAllocatedProvincesByIWorker(iWorkerID);
	}

	// 根据城市Code返回城市
	@RequestMapping("/countByCityCode")
	public @ResponseBody List<Territory> countByCityCode(String cityCode) {
		return provinceService.selectCountByCityCode(cityCode);
	}
}
